package com.cy.core;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class ServerContext {

	private static Map<String,String> servletMapping = new HashMap<String,String>();
	
	static {
		initServletMapping();
	}

	private static void initServletMapping() {
		try {
			SAXReader reader = new SAXReader();
			Document doc = reader.read(new File("conf/servlets.xml"));
			Element root = doc.getRootElement();
			List<Element> servletList = root.elements();
			for(Element servletEle : servletList) {
				String uri = servletEle.attributeValue("uri");
				String className = servletEle.attributeValue("class");
				servletMapping.put(uri, className);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static String getServletNameByUri(String uri) {
		return servletMapping.get(uri);
	}
}

















